76d96a
@@ -22,6 +22,9 @@
 package org.jboss.as.ejb3.tx;
 
 import javax.ejb.TransactionAttributeType;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 
 import org.jboss.as.ee.component.Component;
 import org.jboss.as.ee.component.ComponentInterceptorFactory;
@@ -38,7 +41,7 @@
import org.jboss.invocation.proxy.MethodIdentifier;
  *
  * @author <a href="mailto:cdewolf@redhat.com">Carlo de Wolf</a>
  */
-public class LifecycleCMTTxInterceptor extends CMTTxInterceptor implements Interceptor {
+public class LifecycleCMTTxInterceptor extends CMTTxInterceptor {
 
     private final TransactionAttributeType transactionAttributeType;
     private final int transactionTimeout;
@@ -48,7 +51,6 @@
public class LifecycleCMTTxInterceptor extends CMTTxInterceptor implements Inter
         this.transactionTimeout = transactionTimeout;
     }
 
-
     @Override
     public Object processInvocation(InterceptorContext invocation) throws Exception {
         final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
@@ -71,6 +73,32 @@
public class LifecycleCMTTxInterceptor extends CMTTxInterceptor implements Inter
         }
     }
 
+    @Override
+    protected Object notSupported(InterceptorContext invocation, EJBComponent component) throws Exception {
+        TransactionManager tm = component.getTransactionManager();
+        Transaction tx = tm.getTransaction();
+        int status = (tx != null) ? tx.getStatus() : Status.STATUS_NO_TRANSACTION;
+        // If invocation was triggered from Synchronization.afterCompletion(...)
+        // then skip suspend/resume of associated tx since JTS refuses to resume a completed tx
+        switch (status) {
+            case Status.STATUS_NO_TRANSACTION:
+            case Status.STATUS_COMMITTED:
+            case Status.STATUS_ROLLEDBACK: {
+                return this.invokeInNoTx(invocation, component);
+            }
+            default: {
+                Transaction suspendedTx = tm.suspend();
+                try {
+                    return this.invokeInNoTx(invocation, component);
+                } finally {
+                    if (suspendedTx != null) {
+                        tm.resume(suspendedTx);
+                    }
+                }
+            }
+        }
+    }
+
     /**
      * @author Stuart Douglas
      */
